package com.mew.chess.core.game.lh.game.message;

import com.mew.chess.core.common.message.response.ChipMessage;
import com.mew.chess.core.game.lh.game.common.LhBetType;
import com.zebra.common.ZebraBaseMessage;
import io.netty.buffer.ByteBuf;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;


@Data
@ToString
@NoArgsConstructor
public class LhPushBetInfoMessage extends ZebraBaseMessage<LhPushBetInfoMessage> {

    private List<Long> betNumbers = Arrays.stream(new long[LhBetType.values().length]).boxed().collect(Collectors.toList()); //bet number

    private List<ChipMessage> chipList = new ArrayList<>(); //筹码

    @Override
    public void write(ByteBuf b) {


        writeMsg(b);
    }

    public void writeMsg(ByteBuf b){
        writeLongArray(b,betNumbers.stream().mapToLong(l->l).toArray());
        writeInt(b,chipList.size());
        for (ChipMessage list : chipList) {
            list.write(b);
        }
    }


    @Override
    public LhPushBetInfoMessage read(ByteBuf b) {
        return null;
    }

    public void clearInfo(){
        betNumbers = Arrays.stream(new long[LhBetType.values().length]).boxed().collect(Collectors.toList());

        chipList = new ArrayList<>();
    }

    public void clearInfoList(){

        chipList = new ArrayList<>();
    }

    public void addBetInfo(long uid,int type ,long gold){
        betNumbers.set(type,betNumbers.get(type)+gold);
        chipList.add(ChipMessage.builder().userId(uid).betNumber(gold).betType(type).build());
    }

}
